package com.guaoran.config;

import com.guaoran.entity.SystemOptr;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * @author : 孤傲然
 * @Description :
 * @date :2018/1/25 16:58
 */

@Component
public class SpringSecurityAuditorAware implements AuditorAware<String> {
    @Override
    public String getCurrentAuditor() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null || !authentication.isAuthenticated()) {
            return "admin";
        }
        return ((SystemOptr) authentication.getPrincipal()).getName();
    }
}
